<template>
  <div class="tenantMenu_main main_container">
    <div v-loading="loading" class="main_main">
      <div class="SearchBar_main main_main_search">
        <div class="main_main_search_item">
          <div class="formItem_header">
            <div class="formItem_header_operate">
              <a class="formItem_header_operate_items" @click="add">
                <svg-icon icon-class="新增" />
                <div class="item_name">新增</div>
              </a>
            </div>
          </div>
        </div>
        <div class="main_main_search_item search_input_div">
          <el-input v-model="pageData.searchValue" class="search_input" placeholder="请输入工艺路线编码或工艺名称" clearable @keyup.enter.native="()=>{pageData.pageNum=1; getList()}" @clear="getList" />
          <el-button class="button_icon" icon="el-icon-search" @click.stop="()=>{pageData.pageNum=1; getList()}" />
        </div>
      </div>
      <div ref="table_container" class="table_container">
        <el-table
          ref="table"
          :data="tableData"
          :row-class-name="tableRowClass"
          :height="tableHeight"
          stripe
          border
          style="width: 99.9%"
          @row-click="chooseProcessFlow"
        >
          <Column v-for="(column,index) in defaultTableColumns" :key="index" :prop="column.prop" :is-show="column.isShow" :label="column.label" :sortable="column.sortable" :width="column.width" />
        </el-table>
      </div>
    </div>
    <div class="main_bottom">
      <pagination
        :total="total"
        :page.sync="pageData.pageNum"
        :limit.sync="pageData.pageSize"
        :selected-num="selectionsAll.length"
        @pagination="getList"
      />
    </div>

  </div>
</template>

<script>
import { list } from '@/api/engineeringManage/processFlow'
import AddOrUpdate from './addOrUpdate.vue' // 新增或编辑页面
export default {
  props: {
    layerid: {},
    currentIndex: {},
    selectedRow: {},
    id: {}
  },
  data() {
    return {
      templateSelection: '',
      loading: false,
      pageData: {
        status: 1,
        pageNum: 1,
        pageSize: 20,
        orderByColumn: 'updateTime',
        isAsc: 'desc',
        searchValue: ''
      },
      // tableKey: 1,
      total: 1, // 数据一共有多少条
      mainId: 'id', // 表格行ID
      tableHeight: '0', // 表格高度
      tableData: [], // 表格数据
      tableColumns: [], // 表格实际用的字段
      searchColumns: [], // 搜索区实际用的字段
      selections: [], // 表格当前页所选中的行
      selectionsAll: [], // 表格所有页选中的行
      defaultTableColumns: [// 表格常规字段（初始值）
        { prop: 'code', label: '工艺路线编码' },
        { prop: 'name', label: '工艺路线名称' },
        { prop: 'versionCode', label: '版本号' },
        { prop: 'remark', label: '备注' }
      ]
    }
  },
  created() {
  },
  mounted() {
    this.getList()
    if (this.selectedRow) {
      this.templateSelection = this.selectedRow
    }

    this.$nextTick(() => {
      this.tableHeight = this.$refs.table_container.offsetHeight
    })
  },
  methods: {
    tableRowClass({ row }) {
      if (row.id == this.templateSelection) {
        return 'rowSelected'
      } else {
        return ''
      }
    },
    getList() {
      list(this.pageData).then(res => {
        this.total = res.total
        this.tableData = res.data
      })
    },
    refresh() {
      this.pageData.pageNum = 1
      this.getList()
    },
    add() {
      this.$layer.iframe({// 弹框
        content: {
          content: AddOrUpdate, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: {
            tag: 'add'
          }// props
        },
        area: ['1320px', '850px'],
        title: '新增工艺路线', // 标题
        shadeClose: false // 点击遮罩是否关闭
      })
    },
    chooseProcessFlow(row) {
      this.$parent.chooseProcessFlowCallBack(row, this.currentIndex)
      this.$layer.close(this.layerid)
    }
  }
}
</script>

<style lang="less" scoped>
.button{
    width: 100px;
    height: 30px;
    color: #fff;
    background-color: #387bfc;
    border-radius: 4px;
    text-align: center;
    line-height: 30px;
}
.formItem_header_operate_items{
  height: 30px;
  display: flex;justify-content: center;align-items: center;
  padding: 0px 10px;font-size: 16px;border-radius: 4px;
  color: rgba(56, 123, 252, 1);background-color: rgba(235, 242, 255, 1);
  .item_name{
    font-size: 14px;padding-left: 10px;
  }
}
.formItem_header_operate_items:hover{
  background-color: rgba(235, 242, 255, 0.5);
}

.table_container{
  margin-top: 20px !important;
}
.addtype-main_bottoms{
  padding-right: 20px !important;
  margin: 10px 0;
}
.main_search_item{
  padding-right: 20px !important;
}
.main_main_search{
  padding-right: 20px !important;
}
.main_main_search_item{
  padding-left: 20px !important;
}
.main_main{
    margin: 0 !important;
  padding-top:0 !important;
  height: calc(100% - 50px) !important;

}
.button_icon{
 background:#387bfc;
 width:30px;
}
.search_input{
  width:240px;
  margin-right:10px
}
/deep/ .el-table--enable-row-hover .el-table__body tr:hover > td {
  background-color: rgba(56, 123, 252, 0.5) !important;
  color: #ffffff;
}
.search_input_div{
  width: 300px !important;
}
</style>
